
using System;
using System.Diagnostics;
using System.IO;
using System.Collections.Generic;

//svnkit imports
using org.tmatesoft.svn.core;
using org.tmatesoft.svn.core.wc;


namespace Subsync.Core.Subversion
{
	
	
	public class SVNAdminCreate : CommandBase
	{
        /// <summary>
        /// We have our variables declared here.
        /// Access modifiers as you can observe, is public. Why?
        /// Because we trust our programmers.
        /// 
        /// Try to be verbose with the variable names.
        /// Also, try to include *sane defaults*. Take peg_revision for eg.
        /// </summary>
        
        public java.io.File path;
        public string uuid;
        public bool enableRevisionProperties;
        public bool force = false;
        public bool pre14Compatible;
        public bool pre15Compatible;
        public bool pre16Compatible;

        /// <summary>
        /// Default constructor
        /// </summary>
        public SVNAdminCreate()
        {
        }

		/// <summary>
		/// Minimal constructor
		/// </summary>
        /// <param name="path">
        /// A <see cref="java.io.File"/>
        /// </param>
        /// <param name="uuid">
        /// A <see cref="System.String"/>
        /// </param>
        /// <param name="enableRevisionProperties">
        /// A <see cref="System.Boolean"/>
        /// </param>
        /// <param name="force">
        /// A <see cref="System.Boolean"/>
        /// </param>
        public SVNAdminCreate(java.io.File path, string uuid, bool enableRevisionProperties, bool force)
        {
            this.path = path;
            this.uuid = uuid;
            this.enableRevisionProperties = enableRevisionProperties;
            this.force = force;
        }

        /// <summary>
        /// Detailed constructor
        /// </summary>
        /// <param name="path">
        /// A <see cref="java.io.File"/>
        /// </param>
        /// <param name="uuid">
        /// A <see cref="System.String"/>
        /// </param>
        /// <param name="enableRevisionProperties">
        /// A <see cref="System.Boolean"/>
        /// </param>
        /// <param name="force">
        /// A <see cref="System.Boolean"/>
        /// </param>
        /// <param name="pre14Compatible">
        /// A <see cref="System.Boolean"/>
        /// </param>
        public SVNAdminCreate(java.io.File path, string uuid, bool enableRevisionProperties, bool force, bool pre14Compatible)
        {
            this.path = path;
            this.uuid = uuid;
            this.enableRevisionProperties = enableRevisionProperties;
            this.force = force;
            this.pre14Compatible = pre14Compatible;
        }

        /// <summary>
        /// Detailed constructor
        /// </summary>
        /// <param name="path">
        /// A <see cref="java.io.File"/>
        /// </param>
        /// <param name="uuid">
        /// A <see cref="System.String"/>
        /// </param>
        /// <param name="enableRevisionProperties">
        /// A <see cref="System.Boolean"/>
        /// </param>
        /// <param name="force">
        /// A <see cref="System.Boolean"/>
        /// </param>
        /// <param name="pre14Compatible">
        /// A <see cref="System.Boolean"/>
        /// </param>
        /// <param name="pre15Compatible">
        /// A <see cref="System.Boolean"/>
        /// </param>
        public SVNAdminCreate(java.io.File path, string uuid, bool enableRevisionProperties, bool force, bool pre14Compatible, bool pre15Compatible)
        {
            this.path = path;
            this.uuid = uuid;
            this.enableRevisionProperties = enableRevisionProperties;
            this.force = force;
            this.pre14Compatible = pre14Compatible;
            this.pre15Compatible = pre15Compatible;
        }

        /// <summary>
        /// Detailed constructor
        /// </summary>
        /// <param name="path">
        /// A <see cref="java.io.File"/>
        /// </param>
        /// <param name="uuid">
        /// A <see cref="System.String"/>
        /// </param>
        /// <param name="enableRevisionProperties">
        /// A <see cref="System.Boolean"/>
        /// </param>
        /// <param name="force">
        /// A <see cref="System.Boolean"/>
        /// </param>
        /// <param name="pre14Compatible">
        /// A <see cref="System.Boolean"/>
        /// </param>
        /// <param name="pre15Compatible">
        /// A <see cref="System.Boolean"/>
        /// </param>
        /// <param name="pre16Compatible">
        /// A <see cref="System.Boolean"/>
        /// </param>
        public SVNAdminCreate(java.io.File path, string uuid, bool enableRevisionProperties, bool force, bool pre14Compatible, bool pre15Compatible, bool pre16Compatible)
        {
            this.path = path;
            this.uuid = uuid;
            this.enableRevisionProperties = enableRevisionProperties;
            this.force = force;
            this.pre14Compatible = pre14Compatible;
            this.pre15Compatible = pre15Compatible;
            this.pre16Compatible = pre16Compatible;
        }
		
		public override void Execute ()
		{
            //DEBUG MSG. *Always* include this.
            Debug.WriteLine("SVN AdminCreate Execution");

            //library setup
            Tools.setupLibrary();

            //load up the clients
            SVNClientManager cm = SVNClientManager.newInstance();
            org.tmatesoft.svn.core.wc.admin.SVNAdminClient ac = cm.getAdminClient();

            try
            {
                ac.doCreateRepository(this.path, this.uuid, this.enableRevisionProperties, this.force);
            }
            catch (SVNException e)
            {
                //we convert this exception to a non SVNKit exception.
                //we want to minimize interfacing with SVNkit outside of this namespace (abstraction)
                throw new SVNExecuteException(e.getMessage());
            }
		}

        public override Dictionary<string, List<object>> getTokens()
        {
            Dictionary<string, List<object>> ret = new Dictionary<string, List<object>>();
            ret.Add("adminCreate", new List<object>() { "adminCreate" });
            return ret;
        }

        public override List<KeyValuePair<string, initPointer>> getInitPointers()
        {
            List<KeyValuePair<string, initPointer>> ret = new List<KeyValuePair<string, initPointer>>();
            ret.Add(new KeyValuePair<string, initPointer>("adminCreate", new initPointer(this.handleCLI)));
            return ret;
        }

        public void handleCLI(Dictionary<string, List<object>> tokens)
        {
            if (tokens["adminCreate"].Count != 1)
            {
                Console.WriteLine("Not enough arguments: AdminCreate requires at least 1 arguments (location)");
                return;
            }

            string location = (string)tokens["adminCreate"][0];
            this.path = new java.io.File(location);
            //SVNRepositoryFactory.createLocalRepository(new java.io.File(location), true, false);
            this.Execute();

        }
	}
}
